<template>
    <div class="car-container">
        <div class="car-list">
        <!-- 商品列表区域 -->
        <div class="mui-card" v-for="(item,index) in car" :key="item.id">
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
						<mt-switch v-model="item.selected" @change="selectChange(item.id,item.selected)"></mt-switch>
                        <img src="https://m.360buyimg.com/mobilecms/jfs/t1/102962/5/6810/113002/5df75310E9a735577/794fed9928a58362.jpg!q70.jpg" alt="">
                        <div class="info">
                            <h1>{{item.title}}</h1>
                             <p>
                            <span class="price">￥{{item.price}}</span>
                            <numbox :defaultval="item.count" :goodid="item.id"></numbox>
                            <a href="#" @click.prevent="deletegood(item.id,index)">删除</a>
                             </p>
                        </div>
                       
					</div>
				</div>
        </div>
    </div>
    <!-- 结算区域 -->
        <div class="mui-card">
				<div class="mui-card-content">
					<div class="mui-card-content-inner jiesuan">
						<div class="left">
                            <p>总计(不含运费)</p>
                            <p>已勾选商品<span class="red">{{this.$store.getters.getSelectGoodNum}}</span>件,总价<span class="red">{{this.$store.getters.getSelectGoodPrice}}</span>元</p>
                        </div>
                        <mt-button type="danger">去结算</mt-button>
					</div>
                </div>
    </div>
    </div>
</template>
<style scoped lang="scss">
.car-container{
    .jiesuan{
        display: flex;
        justify-content: space-between;
        align-items: center;
        .left{
            .red{
                color: red;
                font-size: 16px;
            }
        }
    }
    background-color: #eee;
    overflow: hidden;
    .car-list{
        .mui-card-content-inner{
            display: flex;
            align-items: center;
        }
        img{
            width: 60px;
            height: 60px;
        }
        .info{
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            h1{
                font-size: 13px;
            }
            .price{
                color:red;
                font-weight: bold;
            }
        }
    }
}
</style>
<script>
import shopcarnumbox from "../subcomponents/shopcarnumbox.vue"
export default {
    data(){
        return {
            car:[]
        }
    },
    created(){
        this.getGoodList();
    },
    methods:{
        getGoodList(){
            this.car=this.$store.state.car
        },
        deletegood(id,index){
            this.car.splice(index,1);
            this.$store.commit("deletegood",id);
        },
        selectChange(id,state){
            var stateObj={
                id:id,
                state:state
            }
            this.$store.commit("updateSelect",stateObj);
        }
    },
    components:{
        numbox:shopcarnumbox
    }
}
</script>